|
|
|
|
|
|
|
Now open the code window behind the Delete button and add this Visual Basic code: |
|
|
|
|
|
|
|
|
Private Sub cmdDelete_Click()
datTitles.Recordset.Delete ' delete the current record
End Sub |
|
|
|
|
Runtime and Design Time Properties
|
|
|
|
|
RecordSet is a runtime only property of the data control. This property is a reference to the underlying data table defined in the design time RecordSource property. The RecordSet can refer to an existing table in the database or a virtual table, such as a Visual Basic Dynaset or Snapshot. This is covered in more depth on Day 3, ''Visual Basic Database Objects." For now, think of the RecordSet property as a runtime version of the RecordSource property you set when you designed the form. |
|
|
|
|
|
|
|
|
|
|
In the two preceding code snippets, you used the Visual Basic methods AddNew and Delete. You will learn more about these and other Visual Basic methods in the lesson on Day 4, "Creating Data Entry Forms with Bound Controls." |
|
|
|
|
|
|
|
|
Save the project and run the program again. You can now click the Add button and see a blank set of input controls for data entry. Fill them all with some data (refer to Figure 1.9 for an example of a new record), and then move to another record in the table. The data is automatically saved to the data table. You can also use the Delete button to remove any record from the table. First, find the record you just added (it's the last record in the table), and then click the Delete button. Now move to the previous record in the table and try to move forward again to view the record you just deleted. You can't. It's not there! |
|
|
|
|
| |
|
|
|
|
When you entered data into this form, you may have noticed that the tab sequence didn't follow a logical progression. This happened because you added the txtTitles control first, but placed the txtISBN control in the first position on the form. Visual Basic defines the tab order of controls in the sequence they are placed on the form. |
|
|
|
|
|
|
|
|
To correct this problem quickly, select the last control you want in your tab sequence (in this case, the Exit button) and enter 0 in its TabIndex property. Next, select the second-to-last control in the tab sequence (the Delete button) and enter 0 in its TabIndex property. Continue to set all the TabIndex values to zero for all controls in your tab sequence by moving backward through the form. Complete the process by setting the TabIndex value of the txtISBN control to 0. |
|
|
|
|
|
|
|